﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// DisplayTableScript 的摘要描述
/// </summary>
namespace Show.TableScript
{
    public class DisplayTableScript : System.Web.IHttpHandler
    {
        public DisplayTableScript()
        {
            //
            // TODO: 在此加入建構函式的程式碼
            //
        }

        #region IHttpHandler 成員

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                //採用網路封裝資訊
                HttpResponse resp = context.Response;
                HttpRequest req = context.Request;
                //參考下拉式功能表
                String picture = req.Form["drop_images"];
                //this.Response.Write(picture);
                //1.串流 Stream Open架構(接小水管)
                System.IO.FileStream fs = new System.IO.FileStream(picture, 
                    System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
                //2.利用記憶體建立緩衝區(Buffer)
                System.Byte[] buff = new Byte[fs.Length];
                fs.Read(buff, 0, (Int32)fs.Length);
                //去問HttpContext Response物件如何接串流
                System.IO.Stream outS = resp.OutputStream;
                outS.Write(buff, 0, (Int32)fs.Length);
                outS.Flush();
                fs.Close();
            }
            catch (System.IO.FileNotFoundException ex) { }
            catch (System.IO.IOException ex) { }
            catch (Exception ex) { }
        }

        #endregion
    }
}
